import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/config/app_data_cache.dart';
import 'package:app/src/http/bean/ywx_limit.dart';
import 'package:app/src/utils/image_path_utils.dart';

///功能类型
class ReviewType {
  //static String? detailsId = ""; //详情ID(列表跳转到详情页面)
  //static bool isShenhe = false; //判断订单是否已经审核过了。
  //static bool isBack = false; //判断是否已退回

  ///fixme 审核类型
  static var Contract = "Contract"; //            合同审核
  static var Order = "Order"; //               订单审核
  static var Auditaddress = "Auditaddress"; //         送货地址审核
  static var ContractOem = "ContractOem"; //         合同特殊设置审核
  static var OrderDJchek = "OrderDJchek"; //          冻结解冻审核
  static var OrdersChangeFactory = "OrdersChangeFactory"; //  工厂更换审核
  static var DeliveryNotice = "DeliveryNotice"; //       发货审核
  static var PayFreeGoodReturn = "PayFreeReturn"; //    退货审核
  static var ReceiptApply = "Receipt"; //         开票审核
  static var Paynotice = "PayNotice"; //            收款审核（确认收款）
  static var PayFree = "PayFree"; //             免款审核
  static var OtherWorkApplyDoList = "OtherWorkApplyDoList"; //派工审核
  static var CarFreightRates = "CarFreightRates"; //外车运费审核
  static var GuaranteedReview = "GuaranteedReview"; //保底审核
  static var WorkReview = "WorkReview"; //加班审核
  static var PercentageCheck = "PercentageCheck"; //提成审核
  static var ContractRoyaltyRateApplyCheck =
      "ContractRoyaltyRateApplyCheck"; //提成比例审核
  static var LoseApplySure = "LoseApplySure"; //报损审核
  static var MaterialReview = "MaterialReview"; //五金领用审核
  static var GetPurDemandList = "GetPurDemandList"; //原片请购单审核
  static var GetPurDemandListMT02 = "GetPurDemandListMT02"; //辅料请购单审核
  static var GetPurDemandListMT03 = "GetPurDemandListMT03"; //五金请购单审核
  static var GetPurOrder = "GetPurOrder"; //原片采购单审核
  static var GetPurOrderMT02 = "GetPurOrderMT02"; //辅料采购单审核
  static var GetPurOrderMT03 = "GetPurOrderMT03"; //五金采购单审核
  static var GetPurContract = "GetPurContract"; //采购合同审核;原片采购单审核
  static var GetPurContractMT02 = "GetPurContractMT02"; //采购合同审核；辅料采购单审核
  static var GetPurContractMT03 = "GetPurContractMT03"; //采购合同审核；五金采购单审核
  static var GetLogisticsContract = "GetLogisticsContract"; //运输合同审核
  ///fixme 非审核类型；如：发起类型
  static var MaterialRequisition = "MaterialRequisition"; //物料请购
  //ReviewType;
  //"OriginalRequisition"; 原片请购
  //"AccessoriesRequisition"; //辅料请购
  //"HardwareRequisition"; //五金请购
  //"GeneratedRequisition"; //已生成
  static var MaterialRequisition_OriginalRequisition =
      "OriginalRequisition"; //原片请购
  static var MaterialRequisition_AccessoriesRequisition =
      "AccessoriesRequisition"; //辅料请购
  static var MaterialRequisition_HardwareRequisition =
      "HardwareRequisition"; //五金请购
  static var MaterialRequisition_Generated = "GetPurDemandList"; //已生成
  static var MaterialRequisition_NotGenerated = "GetMaterialStock"; //未生成
  static var TicketCenter = "TicketCenter"; //工单中心
  static var Myworkorder = "Myworkorder"; //我的工单
}

///服务器菜单,业务项Id标识。
class YwxIdManager {
  ///fixme YwxItem 的 YwxId ;与服务器的获取菜单权限接口数据相对应。
  ///fixme 审核类型
  static var H0001_1 = "H0001_1"; //1 合同审核 （APP改名成 销售合同审核，电脑ERP上面仍然是合同审核）
  static var N4004_9 = "N4004_9"; //2 订单审核
  static var N4018 = "N4018"; //3 送货地址审核
  static var N4016 = "N4016"; //4 合同特殊设置
  static var N4021_0 = "N4021_0"; //5 冻结解冻审核
  static var N4025_0 = "N4025_0"; //6 工厂更换审核
  static var N6024_0 = "N6024-0"; //7 发货审核
  static var N6027_0 = "N6027-0"; //8 退货审核
  static var N6033_0 = "N6033-0"; //9 开票审核
  static var N6036_0 = "N6036-0"; //10 确认收款
  static var N6039_0 = "N6039-0"; //11 免款审核
  static var H0002_1 = "H0002_1"; //12 派工审核
  //N6064 外车运费上报; N6065 外车运费上报(客服服务部经理); N6066 外车运费上报(财务审批);N6067 外车运费上报(出纳付款)
  //LimitYwxId: ["N6064", "N6065", "N6066", "N6067"]
  static var N6064 = "N6064"; //13 外车运费上报审核
  static var H0003_2 = "H0003_2"; //14 保底审核
  static var RS2600 = "RS2600"; //15 加班审核
  static var N6016 = "N6016"; //17 提成审核
  static var N4029_0 = "N4029_0"; //18 提成比例审核
  static var N6047 = "N6047"; //19 报损审核
  static var N2030 = "N2030"; //20 五金领用审核
  static var N8001_3 = "N8001-3"; //原片请购审核列表
  static var N8001_3MT02 = "N8001-11"; //辅料请购审核列表
  static var N8001_3MT03 = "N8001-12"; //五金请购审核列表
  static var N8002_3 = "N8002-3"; //原片采购审核列表
  static var N8002_3MT02 = "N8013-3"; //辅料采购审核列表
  static var N8002_3MT03 = "N8014-3"; //五金采购审核列表
  static var N605_1_3 = "605_1_3"; //采购合同审核（原片）
  static var N605_1_3MT02 = "605_1_10"; //辅料采购合同审核
  static var N605_1_3MT03 = "605_1_11"; //五金采购合同审核
  static var N605_8_3 = "605_8_3"; //运输合同审核

  ///fixme 非审核类型
  static var N8001_1_3 = "N8001-1-3"; //16 物料请购(自主请购)
  static var N_ticketcenter = "N7206"; //fixme 25 工单中心
  static var N_Myworkorder = "N7208"; //fixme 26 我的工单

  ///获取 YwxId如：H0001_1 -> H0001
  static String getYwxId(String? YwxId) {
    if (YwxId != null) {
      if (YwxId.contains("_")) {
        int index = YwxId.indexOf("_");
        return YwxId.substring(0, index);
      } else if (YwxId.contains("-")) {
        int index = YwxId.indexOf("-");
        return YwxId.substring(0, index);
      }
      return YwxId;
    }
    return "";
  }

  static Map<String?, YwxLimit?> _map = {};

  ///业务项Id和YwxLimit权限绑定
  static put(String? YwxId, YwxLimit? value) {
    if (YwxId != null && value != null) {
      _map[YwxId] = value;
    }
  }

  ///根据业务项Id获取YwxLimit权限
  static YwxLimit? get(String? YwxId) {
    if (YwxId != null) {
      return _map[YwxId];
    }
    return null;
  }

  ///1.合同审核
  // static YwxLimit? get1H0001_1() {
  //   return _map[H0001_1];
  // }

  ///1.合同审核
  static YwxItem? get1H0001_1() {
    return _mapYwxItem[H0001_1];
  }

  ///2.订单审核
  // static YwxLimit? get2N4004_9() {
  //   return _map[N4004_9];
  // }

  ///2.订单审核
  static YwxItem? get2N4004_9() {
    return _mapYwxItem[N4004_9];
  }

  ///3.送货地址审核
  // static YwxLimit? get3N4018() {
  //   return _map[N4018];
  // }

  ///3.送货地址审核
  static YwxItem? get3N4018() {
    return _mapYwxItem[N4018];
  }

  ///4.合同特殊设置
  // static YwxLimit? get4N4016() {
  //   return _map[N4016];
  // }
  ///4.合同特殊设置
  static YwxItem? get4N4016() {
    return _mapYwxItem[N4016];
  }

  ///5.冻结解冻审核
  // static YwxLimit? get5N4021_0() {
  //   return _map[N4021_0];
  // }
  ///5.冻结解冻审核
  static YwxItem? get5N4021_0() {
    return _mapYwxItem[N4021_0];
  }

  ///6.工厂更换审核
  // static YwxLimit? get6N4025_0() {
  //   return _map[N4025_0];
  // }
  ///6.工厂更换审核
  static YwxItem? get6N4025_0() {
    return _mapYwxItem[N4025_0];
  }

  ///7.发货审核
  // static YwxLimit? get7N6024_0() {
  //   return _map[N6024_0];
  // }
  ///7.发货审核
  static YwxItem? get7N6024_0() {
    return _mapYwxItem[N6024_0];
  }

  ///8.退货审核
  // static YwxLimit? get8N6027_0() {
  //   return _map[N6027_0];
  // }
  ///8.退货审核
  static YwxItem? get8N6027_0() {
    return _mapYwxItem[N6027_0];
  }

  ///9.开票审核
  // static YwxLimit? get9N6033_0() {
  //   return _map[N6033_0];
  // }
  ///9.开票审核
  static YwxItem? get9N6033_0() {
    return _mapYwxItem[N6033_0];
  }

  ///10.确认收款
  // static YwxLimit? get10N6036_0() {
  //   return _map[N6036_0];
  // }
  ///10.确认收款
  static YwxItem? get10N6036_0() {
    return _mapYwxItem[N6036_0];
  }

  ///11.免款审核
  // static YwxLimit? get11N6039_0() {
  //   return _map[N6039_0];
  // }
  ///11.免款审核
  static YwxItem? get11N6039_0() {
    return _mapYwxItem[N6039_0];
  }

  ///12.派工审核
  // static YwxLimit? get12H0002_1() {
  //   return _map[H0002_1];
  // }
  ///12.派工审核
  static YwxItem? get12H0002_1() {
    return _mapYwxItem[H0002_1];
  }

  ///13.外车运费上报审核
  // static YwxLimit? get13N6064() {
  //   return _map[N6064];
  // }
  ///13.外车运费上报审核
  static YwxItem? get13N6064() {
    return _mapYwxItem[N6064];
  }

  ///14.保底审核
  // static YwxLimit? get14H0003_2() {
  //   return _map[H0003_2];
  // }
  ///14.保底审核
  static YwxItem? get14H0003_2() {
    return _mapYwxItem[H0003_2];
  }

  //15 加班审核 RS2600
  // static YwxLimit? get15RS2600() {
  //   return _map[RS2600];
  // }
  //15 加班审核 RS2600
  static YwxItem? get15RS2600() {
    return _mapYwxItem[RS2600];
  }

  //17 提成审核
  // static YwxLimit? getN6016() {
  //   return _map[N6016];
  // }
  ///17 提成审核
  static YwxItem? getN6016() {
    return _mapYwxItem[N6016];
  }

  //18 提成比例审核
  // static YwxLimit? getN4029_0() {
  //   return _map[N4029_0];
  // }
  ///18 提成比例审核
  static YwxItem? getN4029_0() {
    return _mapYwxItem[N4029_0];
  }

  ///19 报损审核
  static YwxItem? getN6047() {
    return _mapYwxItem[N6047];
  }

  ///N2030 20 五金领用审核
  static YwxItem? getN2030() {
    return _mapYwxItem[N2030];
  }

  ///N8001_3 原片请购单审核
  static YwxItem? getN8001_3() {
    return _mapYwxItem[N8001_3];
  }

  ///N8001_3 辅料请购单审核
  static YwxItem? getN8001_3MT02() {
    return _mapYwxItem[N8001_3MT02];
  }

  ///N8001_3 五金请购单审核
  static YwxItem? getN8001_3MT03() {
    return _mapYwxItem[N8001_3MT03];
  }

  ///N8002_3 原片采购单审核
  static YwxItem? getN8002_3() {
    return _mapYwxItem[N8002_3];
  }

  ///N8002_3 辅料采购单审核
  static YwxItem? getN8002_3MT02() {
    return _mapYwxItem[N8002_3MT02];
  }

  ///N8002_3 五金采购单审核
  static YwxItem? getN8002_3MT03() {
    return _mapYwxItem[N8002_3MT03];
  }

  ///N605_1_3 采购合同审核(原片)
  static YwxItem? getN605_1_3() {
    return _mapYwxItem[N605_1_3];
  }

  ///N605_1_3 辅料采购合同审核
  static YwxItem? getN605_1_3MT02() {
    return _mapYwxItem[N605_1_3MT02];
  }

  ///N605_1_3 五金采购合同审核
  static YwxItem? getN605_1_3MT03() {
    return _mapYwxItem[N605_1_3MT03];
  }

  ///N605_8 运输合同审核
  static YwxItem? getN605_8_3() {
    return _mapYwxItem[N605_8_3];
  }

  ///25.工单中心
  static YwxItem? getN_ticketcenter() {
    return _mapYwxItem[N_ticketcenter];
  }

  ///26.我的工单
  static YwxItem? getN_Myworkorder() {
    return _mapYwxItem[N_Myworkorder];
  }

  static Map<String?, YwxItem?> _mapYwxItem = {};

  ///全部功能
  static List<YwxItem> _allItems = [];

  static _addItem(YwxItem item) {
    _mapYwxItem[item.YwxId] = item;
    if (item.isHasLimit()) {
      _allItems.add(item);
    }
  }

  ///获取合同审核
  static YwxItem getYwxItemWithContract(BuildContext context) {
    return YwxItem(
        YwxId: H0001_1,
        ReviewType: ReviewType.Contract,
        YwxName: AppStrings.of(context).Contract2,
        //销售合同审核
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_011.png'),
        LimitYwxId: [
          "605_1_1",
          "605_1_2",
          "H0001_0",
          "H0001_1",
          "H0001_2",
          "H0001_3",
          "H0001_4",
          "H0001_9"
        ]);
  }

  ///获取全部功能
  ///isReset 数据是否重置
  static List<YwxItem> getAllItems(BuildContext? context,
      {bool isReset = false}) {
    if (!isReset && _allItems.length > 0) {
      return _allItems;
    }
    _allItems.clear();
    if (context == null) {
      return _allItems;
    }
    // LimitYwxId: ["", "", "", "",""]
    ///fixme 审核类
    //1.合同审核
    _addItem(getYwxItemWithContract(context));
    //2.订单审核
    _addItem(YwxItem(
        YwxId: N4004_9,
        ReviewType: ReviewType.Order,
        YwxName: AppStrings.of(context).Order,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_019.png'),
        LimitYwxId: ["N4004_0", "N4004_1", "N4004_10", "N4004_2", "N4004_9"]));
    //3.送货地址审核
    _addItem(YwxItem(
        YwxId: N4018,
        ReviewType: ReviewType.Auditaddress,
        YwxName: AppStrings.of(context).Auditaddress,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_110.png'),
        LimitYwxId: ["N4018", "N4019", "N4020"]));
    //4.合同特殊设置；改名：销售合同特殊设置审核
    _addItem(YwxItem(
        YwxId: N4016,
        ReviewType: ReviewType.ContractOem,
        YwxName: AppStrings.of(context).ContractOem2,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_0111.png'),
        LimitYwxId: ["N4013", "N4015", "N4016", "N4017"]));
    //5.冻结解冻审核
    _addItem(YwxItem(
        YwxId: N4021_0,
        ReviewType: ReviewType.OrderDJchek,
        YwxName: AppStrings.of(context).OrderDJchek,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_0118.png'),
        LimitYwxId: ["N4021_0", "N4022", "N4023", "N4024"]));
    //6.工厂更换审核
    _addItem(YwxItem(
        YwxId: N4025_0,
        ReviewType: ReviewType.OrdersChangeFactory,
        YwxName: AppStrings.of(context).OrdersChangeFactory,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_0119.png'),
        LimitYwxId: ["N4025_1", "N4025_2", "N4025_3"]));
    //7.发货审核
    _addItem(YwxItem(
        YwxId: N6024_0,
        ReviewType: ReviewType.DeliveryNotice,
        YwxName: AppStrings.of(context).DeliveryNotice,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_633.png'),
        LimitYwxId: ["N6024", "N6024-0", "N6024-0", "N6025", "N6026"]));
    //8.退货审核
    _addItem(YwxItem(
        YwxId: N6027_0,
        ReviewType: ReviewType.PayFreeGoodReturn,
        YwxName: AppStrings.of(context).PayFreeGoodReturn,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_634.png'),
        LimitYwxId: [
          "F5008",
          "N5061",
          "N5062_1",
          "N5063_1",
          "N6027",
          "N6027-0",
          "N6028",
          "N8007",
          "N8007_2"
        ]));
    //9.开票审核
    _addItem(YwxItem(
        YwxId: N6033_0,
        ReviewType: ReviewType.ReceiptApply,
        YwxName: AppStrings.of(context).ReceiptApply,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_641.png'),
        LimitYwxId: ["N6033", "N6033-0", "N6034"]));
    //10.确认收款
    _addItem(YwxItem(
        YwxId: N6036_0,
        ReviewType: ReviewType.Paynotice,
        YwxName: AppStrings.of(context).Paynotice,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_643.png'),
        LimitYwxId: ["N6036", "N6036-0", "N6037", "N6038"]));
    //11.免款审核
    _addItem(YwxItem(
        YwxId: N6039_0,
        ReviewType: ReviewType.PayFree,
        YwxName: AppStrings.of(context).PayFree,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_644.png'),
        LimitYwxId: ["N6039", "N6039-0", "N6040", "N6041", "N6042"]));
    //12.派工审核
    _addItem(YwxItem(
        YwxId: H0002_1,
        ReviewType: ReviewType.OtherWorkApplyDoList,
        // YwxId: H0001_1,//暂时用合同审核的测试
        // ReviewType: ReviewType.Contract,
        YwxName: AppStrings.of(context).Dispatchingaudit,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_012.png'),
        LimitYwxId: ["H0002_1", "H0002_2", "H0002_3", "H0002_4", "H0002_0"]));
    //LimitYwxId: ["", "", "", "",""]
    //13.外车运费审核
    _addItem(YwxItem(
        YwxId: N6064,
        ReviewType: ReviewType.CarFreightRates,
        // YwxId: H0001_1,//暂时用合同审核的测试
        // ReviewType: ReviewType.Contract,
        YwxName: AppStrings.of(context).CarFreightRates,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_013.png'),
        LimitYwxId: ["N6064", "N6065", "N6066", "N6067"]));
    // // //14 H0003_2 保底审核
    _addItem(YwxItem(
        YwxId: H0003_2,
        ReviewType: ReviewType.GuaranteedReview,
        // YwxId: H0001_1,//暂时用合同审核的测试
        // ReviewType: ReviewType.Contract,
        YwxName: AppStrings.of(context).GuaranteedReview,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_014.png'),
        LimitYwxId: ["H0003_0", "H0003_1", "H0003_2", "H0003_5"]));
    // // //15 RS2600 加班审核
    _addItem(YwxItem(
        YwxId: RS2600,
        ReviewType: ReviewType.WorkReview,
        // YwxId: H0001_1,//暂时用合同审核的测试
        // ReviewType: ReviewType.Contract,
        YwxName: AppStrings.of(context).WorkReview,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_015.png'),
        LimitYwxId: ["RS2600", "RS2600_0", "RS2600_1"]));

    ///17: 提成审核
    ///    // 提成审核列表	N6016-0	是否具备权限：true
    //     // 提成审核列表	N6016-0	是否具备权限：true
    //     // 提成审核列表	N6016-0	是否具备权限：true
    //     // 提成审核列表	N6016-0	是否具备权限：true
    _addItem(YwxItem(
        YwxId: N6016,
        ReviewType: ReviewType.PercentageCheck,
        YwxName: AppStrings.of(context).PercentageCheck,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_017.png'),
        LimitYwxId: [
          "N6016-0",
          "N6016-1",
          "N6017",
          "N6017-0",
          "N6018",
          "N6018-0",
          "N6019",
          "N6019-0",
          "N6020",
          "N6020-0"
        ]));

    ///18:提成比例审核 ContractRoyaltyRateApplyCheck
    _addItem(YwxItem(
        YwxId: N4029_0,
        ReviewType: ReviewType.ContractRoyaltyRateApplyCheck,
        YwxName: AppStrings.of(context).ContractRoyaltyRateApplyCheck,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_018.png'),
        LimitYwxId: ["N4029_1", "N4029", "N4029_0"]));

    ///19:报损审核
    _addItem(YwxItem(
        YwxId: N6047,
        ReviewType: ReviewType.LoseApplySure,
        YwxName: AppStrings.of(context).LoseApplySure,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N6047.png'),
        LimitYwxId: ["N6047", "N6047-0", "N6048"]));

    ///N2030 20 五金领用审核
    _addItem(YwxItem(
        YwxId: N2030,
        ReviewType: ReviewType.MaterialReview,
        YwxName: AppStrings.of(context).HardwareApproval,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N2030.png'),
        LimitYwxId: [
          "N2030", //fixme  五金领用审核(列表) 单权限控制。
          // "N2031",
          // "N2032",
          // "N2034",
          // "N2034-1"
        ]));

    ///请购单审核
    // _addItem(YwxItem(
    //     YwxId: N8001_3,
    //     ReviewType: ReviewType.GetPurDemandList,
    //     YwxName: AppStrings.of(context).GetPurDemandList,
    //     ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N8001_3.png'),
    //     LimitYwxId: [
    //       "N8001-3", //单权限控制
    //     ]));

    ///原片请购单审核
    _addItem(YwxItem(
        YwxId: N8001_3,
        ReviewType: ReviewType.GetPurDemandList,
        YwxName: AppStrings.of(context).GetPurDemandListMT01,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N8001_3.png'),
        LimitYwxId: [
          "N8001-3", //fixme 单权限控制,原片的和之前的是一样的。
          // "N2030",
          // "N2031",
          // "N2032",
          // "N2034",
          // "N2034-1",
          // "N8001-2",
          // "N8001-6"
        ]));

    ///辅料请购单审核
    _addItem(YwxItem(
        YwxId: N8001_3MT02,
        ReviewType: ReviewType.GetPurDemandListMT02,
        YwxName: AppStrings.of(context).GetPurDemandListMT02,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N8001_3.png'),
        LimitYwxId: [
          "N8001-11", //单权限控制
          // "N2030",
          // "N2031",
          // "N2032",
          // "N2034",
          // "N2034-1",
          // "N8001-2",
          // "N8001-6"
        ]));

    ///五金请购单审核
    _addItem(YwxItem(
        YwxId: N8001_3MT03,
        ReviewType: ReviewType.GetPurDemandListMT03,
        YwxName: AppStrings.of(context).GetPurDemandListMT03,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N8001_3.png'),
        LimitYwxId: [
          "N8001-12", //单权限控制
          // "N2030",
          // "N2031",
          // "N2032",
          // "N2034",
          // "N2034-1",
          // "N8001-2",
          // "N8001-6"
        ]));

    ///采购单审核 N8002_3 PurOrder
    // _addItem(YwxItem(
    //     YwxId: N8002_3,
    //     ReviewType: ReviewType.GetPurOrder,
    //     YwxName: AppStrings.of(context).PurOrder,
    //     ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N8002_3.png'),
    //     LimitYwxId: [
    //       "N8002-3", //单权限控制
    //     ]));

    ///原片采购单审核 N8002_3 PurOrder
    _addItem(YwxItem(
        YwxId: N8002_3,
        ReviewType: ReviewType.GetPurOrder,
        YwxName: AppStrings.of(context).PurOrderMT01,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N8002_3.png'),
        LimitYwxId: [
          "N8002-3", //单权限控制
          // "N8002",
          // "N8002-1",
          // "N8002-11",
          // "N8002-5",
          // "N8002-7",
          // "N8002-8",
          // "N8002-8-1",
          // "N8002-8-10",
          // "N8002-8-11",
          // "N8002-8-2",
          // "N8002-8-3",
          // "N8002-8-4",
          // "N8002-8-5",
          // "N8002-8-6",
          // "N8002-8-7",
          // "N8002-8-8",
          // "N8002-8-9"
        ]));

    ///辅料采购单审核
    _addItem(YwxItem(
        YwxId: N8002_3MT02,
        ReviewType: ReviewType.GetPurOrderMT02,
        YwxName: AppStrings.of(context).PurOrderMT02,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N8002_3.png'),
        LimitYwxId: [
          "N8013-3", //单权限控制
        ]));

    ///五金采购单审核
    _addItem(YwxItem(
        YwxId: N8002_3MT03,
        ReviewType: ReviewType.GetPurOrderMT03,
        YwxName: AppStrings.of(context).PurOrderMT03,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N8002_3.png'),
        LimitYwxId: [
          "N8014-3", //单权限控制
        ]));

    ///N605_1_3 采购合同审核
    // _addItem(YwxItem(
    //     YwxId: N605_1_3,
    //     ReviewType: ReviewType.GetPurContract,
    //     YwxName: AppStrings.of(context).GetPurContract,
    //     ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N605_1_3.png'),
    //     LimitYwxId: [
    //       "605_1_3", //单权限控制
    //     ]));

    //N605_1_3 原片采购合同审核
    _addItem(YwxItem(
        YwxId: N605_1_3,
        ReviewType: ReviewType.GetPurContract,
        YwxName: AppStrings.of(context).GetPurContractMT01,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N605_1_3.png'),
        LimitYwxId: [
          "605_1_3", //单权限控制
        ]));

    //N605_1_3 辅料采购合同审核
    _addItem(YwxItem(
        YwxId: N605_1_3MT02,
        ReviewType: ReviewType.GetPurContractMT02,
        YwxName: AppStrings.of(context).GetPurContractMT02,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N605_1_3.png'),
        LimitYwxId: [
          "605_1_10", //单权限控制
        ]));

    //N605_1_3 五金采购合同审核
    _addItem(YwxItem(
        YwxId: N605_1_3MT03,
        ReviewType: ReviewType.GetPurContractMT03,
        YwxName: AppStrings.of(context).GetPurContractMT03,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N605_1_3.png'),
        LimitYwxId: [
          "605_1_11", //单权限控制
        ]));

    ///N605_8 运输合同审核
    _addItem(YwxItem(
        YwxId: N605_8_3,
        ReviewType: ReviewType.GetLogisticsContract,
        YwxName: AppStrings.of(context).GetLogisticsContract,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N605_8_3.png'),
        LimitYwxId: [
          // "605_8",
          // "605_8",
          // "605_8_0",
          // "605_8_1",
          // "605_8_2",
          "605_8_3", //运输合同审核列表 单权限控制
        ]));

    ///fixme 非审核类
    // // //16 N8001 物料请购
    _addItem(YwxItem(
        YwxId: N8001_1_3,
        ReviewType: ReviewType.MaterialRequisition,
        // YwxId: H0001_1,//暂时用合同审核的测试
        // ReviewType: ReviewType.Contract,
        YwxName: AppStrings.of(context).MaterialRequisition,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_641.png'),
        LimitYwxId: [
          "N8001-1",
          "N8001-1-3",
          "N8001-4",
          "N8001-5"
        ])); //物料请购: 请求申请权限， 自主请购权限,请购查看权限
    ///fixme 工单中心 {"YwxId":"N7206","YwxName":"工单中心","Group":"1000","HasLimit":"True"}
    _addItem(YwxItem(
        YwxId: N_ticketcenter,
        ReviewType: ReviewType.TicketCenter,
        // YwxId: H0001_1,//暂时用合同审核的测试
        // ReviewType: ReviewType.Contract,
        YwxName: AppStrings.of(context).Ticket_center,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N2030.png'),
        LimitYwxId: ["N7206"])); //
    ///fixme 我的工单
    _addItem(YwxItem(
        YwxId: N_Myworkorder,
        ReviewType: ReviewType.Myworkorder,
        // YwxId: H0001_1,//暂时用合同审核的测试
        // ReviewType: ReviewType.Contract,
        YwxName: AppStrings.of(context).Myworkorder,
        ImagePath: ImagePathUtils.getPathWithImageItem('ic_work_N2030.png'),
        LimitYwxId: ["N7208"])); //
    return _allItems;
  }

  ///常用功能
  static List<YwxItem> _useItems = [];

  ///获取常用功能
  static List<YwxItem> getUsedItems(BuildContext context,
      {bool isReset = true}) {
    if (!isReset && _useItems.length > 0) {
      return _useItems;
    }
    _useItems.clear();
    getAllItems(context, isReset: isReset)?.forEach((element) {
      if (AppDataCache.containsUsedItems(element.YwxId)) {
        _useItems.add(element);
      }
    });
    // print('====================常用功能个数${_useItems?.length}');
    return _useItems;
  }

  ///非常用功能
  static List<YwxItem> _nouseItems = [];

  ///获取非常用功能
  static List<YwxItem> getNoUsedItems(BuildContext context,
      {bool isReset = true}) {
    if (!isReset && _nouseItems.length > 0) {
      return _nouseItems;
    }
    _nouseItems.clear();
    getAllItems(context, isReset: isReset)?.forEach((element) {
      if (!AppDataCache.containsUsedItems(element.YwxId)) {
        _nouseItems.add(element);
      }
    });
    // print('====================非常用功能个数${_nouseItems?.length}');
    return _nouseItems;
  }

  ///获取指定的YwxItem
  static YwxItem? getYwxItem(BuildContext? context,
      {String? ReviewType, String? YwxId}) {
    YwxItem? item = null;
    String YwxId2 = getYwxId(YwxId).trim();
    getAllItems(context)?.forEach((element) {
      if (item == null) {
        if (StringUtils.isNotEmpty(ReviewType)) {
          // print(
          //     "${ReviewType?.trim()}\t${element.ReviewType?.trim()}\t${(ReviewType?.trim() == element.ReviewType?.trim())}");
          //fixme 以ReviewType为优先。YwxId本地可能与服务器对不上。
          if (ReviewType?.trim() == element.ReviewType?.trim()) {
            item = element;
          }
        }
      }
    });
    if (item == null) {
      getAllItems(context)?.forEach((element) {
        if (item == null) {
          if (StringUtils.isNotEmpty(YwxId)) {
            if (YwxId?.trim() == element.YwxId?.trim()) {
              //print("==========================================================进来了1:${YwxId?.trim()}\t${element.YwxId?.trim()}");
              item = element;
            }
          }
          if (item == null) {
            String YwxId3 = getYwxId(element.YwxId).trim();
            if (YwxId2 == YwxId3) {
              //YwxId:N4023	YwxId2:	YwxId3:		element.YwxId:	N4018
              //print("==========================================================进来了2:\tYwxId:$YwxId\tYwxId2:${YwxId2}\tYwxId3:\t${YwxId3}\telement.YwxId:\t${element.YwxId}");
              item = element;
            }
          }
        }
      });
    }
    // print('====================非常用功能个数${_nouseItems?.length}');
    return item;
  }

  ///随便获取一个默认的YwxItem；方便测试
  static YwxItem? getDefaultYwxItem() {
    if (_nouseItems.length > 0) {
      return _nouseItems[0];
    }
    if (_useItems.length > 0) {
      return _useItems[0];
    }
    return null;
  }
}
